﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentAlarmItemVMs
{
    public partial class EquipmentAlarmItemListVM : BasePagedListVM<EquipmentAlarmItem_View, EquipmentAlarmItemSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipmentAlarmItem_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentAlarmItem_View>>{

                this.MakeGridHeader(x => x.EquipmentAlarmItem_EquipName).SetTitle(@Localizer["Page.设备名称"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_EquipmentId).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_EquipTag).SetTitle(@Localizer["Page.变量"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_EquipTagName).SetTitle(@Localizer["Page.变量名称"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_EquipTagAddress).SetTitle(@Localizer["Page.变量地址"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_Content).SetTitle(@Localizer["Page.报警内容"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_Level).SetTitle(@Localizer["Page.报警级别"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_Classify).SetTitle(@Localizer["Page.报警分类"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_Bits).SetTitle(@Localizer["Page.位"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentAlarmItem_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentAlarmItem_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentAlarmItem>()
                
                .CheckContain(Searcher.EquipName, x=>x.EquipName)
                .CheckEqual(Searcher.EquipTagId, x=>x.EquipTagId)
                .CheckContain(Searcher.EquipTagName, x=>x.EquipTagName)
                .CheckContain(Searcher.EquipTagAddress, x=>x.EquipTagAddress)
                .CheckContain(Searcher.Content, x=>x.Content)
                .CheckEqual(Searcher.Level, x=>x.Level)
                .CheckEqual(Searcher.Classify, x=>x.Classify)
                .CheckEqual(Searcher.Bits, x=>x.Bits)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EquipmentAlarmItem_View
                {
				    ID = x.ID,
                    
                    EquipmentAlarmItem_EquipName = x.EquipName,
                    EquipmentAlarmItem_EquipTag = x.EquipTag.TenantCode,
                    EquipmentAlarmItem_EquipTagName = x.EquipTagName,
                    EquipmentAlarmItem_EquipmentId=x.EquipmentId,
                    EquipmentAlarmItem_EquipTagAddress = x.EquipTagAddress,
                    EquipmentAlarmItem_Content = x.Content,
                    EquipmentAlarmItem_Level = x.Level,
                    EquipmentAlarmItem_Classify = x.Classify,
                    EquipmentAlarmItem_Bits = x.Bits,
                    EquipmentAlarmItem_Active = x.Active,
                    EquipmentAlarmItem_CreateTime = x.CreateTime,
                    EquipmentAlarmItem_UpdateTime = x.UpdateTime,
                    EquipmentAlarmItem_CreateBy = x.CreateBy,
                    EquipmentAlarmItem_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipmentAlarmItem_View: EquipmentAlarmItem
    {
        
        public string EquipmentAlarmItem_EquipName { get; set; }


        public long? EquipmentAlarmItem_EquipmentId { get; set; }
        public string EquipmentAlarmItem_EquipTag { get; set; }
        public string EquipmentAlarmItem_EquipTagName { get; set; }
        public string EquipmentAlarmItem_EquipTagAddress { get; set; }
        public string EquipmentAlarmItem_Content { get; set; }
        public AlarmLevelEnum? EquipmentAlarmItem_Level { get; set; }
        public AlarmTypeEnum? EquipmentAlarmItem_Classify { get; set; }
        public int? EquipmentAlarmItem_Bits { get; set; }
        public bool? EquipmentAlarmItem_Active { get; set; }
        public DateTime? EquipmentAlarmItem_CreateTime { get; set; }
        public DateTime? EquipmentAlarmItem_UpdateTime { get; set; }
        public string EquipmentAlarmItem_CreateBy { get; set; }
        public string EquipmentAlarmItem_UpdateBy { get; set; }

    }

}